#import fs from 'fs'

# https://github.com/electron/electron/pull/9824
#process.traceDeprecation = true

import {
  ipcRenderer
  contextBridge
} from 'electron'
import { domReady } from './utils'
import { useLoading } from './loading'
import { upload } from './oss.coffee'
import ipc from './ipc.coffee'

{ ing, xing} = useLoading()

E = Object.freeze {
  drag:=>
    return
  upload:upload(
    ipc.userData
  )
  invoke:(func, args)=>
    ipcRenderer.invoke(func, args)
  xing
  ing
}



do =>

  for k,v of {
    E
  }
    contextBridge.exposeInMainWorld(k,v)

  domReady().then ing

  ###
  {hash} = location

  switch hash[1..]
    when 'main'
      await import('./auto_update.coffee')
  ###
  return

###
withPrototype = (obj) =>
  protos = Object.getPrototypeOf(obj)

  for [key, value] from Object.entries(protos)
    if Object.prototype.hasOwnProperty.call(obj, key)
      continue

    if typeof value == 'function'
      # Some native API not work in Renderer-process, like `NodeJS.EventEmitter['on']`. Wrap a function patch it.
      obj[key] = (...args) =>
        return value.call(obj, ...args)
    else
      obj[key] = value
  return obj
isDev = process.env.NODE_ENV == 'development'
contextBridge.exposeInMainWorld('removeLoading', removeLoading)
contextBridge.exposeInMainWorld('ipcRenderer', withPrototype(ipcRenderer))
###
